package com.xteam.ecsystem.directive;

import static freemarker.template.ObjectWrapper.DEFAULT_WRAPPER;

import java.io.IOException;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xteam.ecsystem.base.Constant;
import com.xteam.ecsystem.entities.BaseReceiveAddress;
import com.xteam.ecsystem.service.front.FrontUserAddrService;
import com.xteam.ecsystem.utils.DirectiveUtil;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

/**
 * 商品信息标签
 * @author ls
 */
@Service
public class ReceiverInfoDirective implements TemplateDirectiveModel {
	
	@Autowired
	private FrontUserAddrService fuaService;
	
	@SuppressWarnings("unchecked")
	public void execute(Environment env, Map params, TemplateModel[] loopVars,
			TemplateDirectiveBody body) throws TemplateException, IOException {
		String memberId = DirectiveUtil.getString(params, Constant.PAR_MEMBERID.value());
		BaseReceiveAddress bra = this.fuaService.getReceiverInfo(memberId);
		env.setVariable(Constant.VAR_RECEIVERINFO.value(),DEFAULT_WRAPPER.wrap(bra));
		body.render(env.getOut());
	}
}